<?php
require_once 'modules/content/models/Content.php';
require_once 'modules/book/models/Book.php';
require_once 'modules/language/models/Lang.php';
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
class test_IndexController extends Nine_Controller_Action
{
	public function indexAction()
	{
        /*
         * created by: nguyentuan
         * date: 08/01/2014
         * create an api to get all the epub file in database and a book.
         * format: localhost/portal/test -> get all book
         *         localhost/portal/test?id=  -> get a book with id
         */
        $objBook = new Models_Book();
        $objLang = new Models_Lang();
        $config = Nine_Registry::getConfig();
        $allBook = $objBook->setAllLanguages(true)->getAllBooks(null, array('book_gid DESC', 'book_id ASC'));
        /*
         * each book
         */
        $gid = $this->_getParam('id');
        //  link http://localhost/portal/test/?id=3
        if ($gid != null) {
            $book = $objBook->setAllLanguages(true)->getBookById($gid);
            print_r(json_encode($book));
            die;
        }
        print_r(json_encode($allBook));
            /*echo $allBook[0]['created_date'];
            echo "\n";
            $allBook[0]['created_date'] = date($config['dateFormat'], $allBook[0]['created_date']);
            echo $allBook[0]['created_date'];
            echo "\n";
            echo $allBook[3]['title'];*/
        die;

	}
    public function nameAction() {
        $this->view->string= "nguyentuan";
        $gid = $this->_getParam('id');
        $this->view->id = $gid;
    }
}